package com.joker.aigc.config;


import com.joker.aigc.intecepter.CollectorInterceptor;
import com.joker.aigc.intecepter.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Description: 配置所有拦截器
 * Author: <a href="https://github.com/zongzibinbin">abin</a>
 * Date: 2023-04-05
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;
    @Autowired
    private CollectorInterceptor collectorInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login")
                .excludePathPatterns("/hello")
                .excludePathPatterns("/api/1.0/tools/**")
                .excludePathPatterns("/api/1.0/online/**")
                .excludePathPatterns("/api/1.0/oss/**")
                .excludePathPatterns("/api/1.0/articles/**")
                .excludePathPatterns("/api/1.0/article-comments/**")
                .excludePathPatterns("/oj/problem/**")
                .excludePathPatterns("/swagger-ui/**")
                .excludePathPatterns("/api/1.0/ai/**")
                .excludePathPatterns("/v1/api-docs/**");

        registry.addInterceptor(collectorInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/hello")
                .excludePathPatterns("/api/1.0/tools/**")
                .excludePathPatterns("/api/1.0/oss/**")
                .excludePathPatterns("/api/1.0/articles/**")
                .excludePathPatterns("/api/1.0/online/**")
                .excludePathPatterns("/api/1.0/article-comments/**")
                .excludePathPatterns("/oj/problem/**")
                .excludePathPatterns("/login")
                .excludePathPatterns("/api/1.0/ai/**")
                .excludePathPatterns("/swagger-ui/**")
                .excludePathPatterns("/v1/api-docs/**");
    }
}
